var main = (function () {
    console.log("main init...");

    var url = location.href;
    var jsUrl = "https://liuzhenghui.gitee.io/chrome-snippets/js/";

    var jsImports = [
        "https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js",
        jsUrl + "beep.js",
    ];

    return {
        load: function (option) {
            var self = this;
            self.createIframe();
            setTimeout(function () {
                var win = top.frames[0].window;
                console.log("win", win);
                self.createSnippetDiv();
                if (option.callback) {
                    option.callback();
                }
            }, 5000);
        },
        createIframe: function () {
            var html = "";
            html += "<head>";
            for (var i = 0; i < jsImports.length; i++) {
                html += "<script language=javascript src='" + jsImports[i] + "'></script>";
            }
            html += "</head>";

            html += "<body><iframe style='border: 0;width: 100%;height: 100%;' src='" + url + "'></iframe></body>";
            document.write(html);
            document.close();
        },
        createSnippetDiv: function () {
            console.log("createSnippetDiv");
            $("body").append("<div id='debug' style='position: absolute;bottom: 3px;right: 3px;width: 100px;height: 30px;background-color: rgba(255,255,0,0.5);padding: 10px;color:#f00;font-size: 10px;'></div>")
            $("#debug").html("调试");
        }
    };
})();